package io.gitee.mojingjiao.day06;

import org.junit.Test;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class LetterOrder {
    @Test
    public void test(){
        String letter="Stack Overflow requires external JavaScript from overflow another or domain," +
            "  which is blocked or failed to or load.";
        Map<Character, Integer> map = countEach(letter);

        for (Map.Entry<Character, Integer> characterIntegerEntry : map.entrySet()) {
            System.out.println(characterIntegerEntry.getKey()+"/"+ characterIntegerEntry.getValue());
        }

    }


    public Map<Character, Integer> countEach( String letter){
        Map<Character, Integer> map = new HashMap<>();
        for (int i = 0; i < letter.length(); i++) {
            char a=letter.charAt(i);
            int x=(int)(a);
//            System.out.println(x);
            if('A'<=x&&'Z'>=x){
                 a=(char)(x+32);
            }

         if(map.containsKey(a)){
             map.put(a,map.get(a)+1);
         }
         else{
             map.put(a,1);
         }

        }
        return map;

    }

}
